package dk.hewison.client.pages;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import dk.hewison.client.Log;


/**
 * @author John Hewison
 * @author $LastChangedBy: john.hewison $:  $ $LastChangedDate: 2009-02-01 11:48:31 +0000 (Sun, 01 Feb 2009) $:
 * @version $Revision: 67 $:
 */
public abstract class Page extends Composite {

    ScrollPanel scrollPanel;
    /*NEffectPanel effectPanel;

    Fade fadeIn;
    Fade fadeOut;*/

    protected Page() {
        /*fadeIn = getFadeIn();
        fadeOut = getFadeOut();


        effectPanel = new NEffectPanel();
        effectPanel.addEffect(fadeIn);
        effectPanel.addEffect(fadeOut);
        effectPanel.setEffectsLength(0.3);*/


        Widget widget = initPage();
        /*effectPanel.add(widget);
        effectPanel.setWidth("100%");*/

        scrollPanel = new ScrollPanel(widget);

        initWidget(scrollPanel);

        doLayout();
    }

    public void setPageListener(final PageListener pageListener) {
        /*fadeOut.addEffectHandler(new NEffectHandlerAdapter() {

            @Override
            public void postEvent(NEffect theEffect) {
                pageListener.pageHidden();
            }
        });*/
    }


    public void showPage() {
        //fadeIn.play();
    }

    public void hidePage() {
        //fadeOut.play();
    }

    protected abstract Widget initPage();

    /*public static Fade getFadeIn() {
        Fade fade = new Fade();
        fadeIn(fade);
        return fade;
    }

    private static void fadeIn(Fade fade) {
        fade.getProperties().setStartOpacity(20);
        fade.getProperties().setEndOpacity(100);
    }

    public static Fade getFadeOut() {
        Fade fade = new Fade();
        fadeOut(fade);
        return fade;
    }

    private static void fadeOut(Fade fade) {
        fade.getProperties().setStartOpacity(100);
        fade.getProperties().setEndOpacity(20);
    }*/

    /*public void setPixelSize(int width, int height) {
        effectPanel.setPixelSize(width, height);
    }*/

    public void doLayout() {
        getWidget().setWidth("100%");
        int top = getAbsoluteTop();
        int clientHeight = Window.getClientHeight();
        scrollPanel.setPixelSize(Window.getClientWidth() - 20, clientHeight - top - 10);
    }

    public void log(String s) {
        Log.debug(s);
    }
}
